<div>
  <h1>欢饮您, <%- user.name %></h1>
  <div>
    <button onclick="logout()">退出登录</button>
    <div id="uid" style="display: none"><%- user.id %></div>
  </div>
</div>
<script>
  function logout() {
    const uid = document.getElementById('uid').innerText;

    fetch(`/auth/logout?uid=${uid}`, {
      method: 'GET',
    }).then(res => {
      sessionStorage.clear();
      localStorage.clear();

      let url;
      if (res.redirected) {
        url = res.url;
      } else {
        url = '/';
      }

      window.location.href = url;
    });
  }
</script>
